package bridge

import (
	"gitee.com/tomatomeatman/golang-repository/bricks3/function/configutil"
	"gitee.com/tomatomeatman/golang-repository/bricks3/function/urlutil"
	"gitee.com/tomatomeatman/golang-repository/bricks3/model/globalvariable"
	"gitee.com/tomatomeatman/golang-repository/bricks3/model/msgentity"
	"github.com/gin-gonic/gin"
)

/**
 * 模块管理ModuleManage表基本业务操作结构体
 */
type ModuleManageService struct {
}

var (
	moduleManageServiceName = "" //桥接到登录服务的服务名,默认GBaseSystemServer
	//moduleManageServiceName  = "" //桥接到登录服务的服务密钥
)

// 初始化
func init() {
	if configutil.HasSection("./config/app.ini", "CloudCenter") { //禁用桥接
		return
	}

	moduleManageServiceName = configutil.ReadConfigKey("", "CloudServer", "BaseServerName", "GBaseSystemServer").(string)
	globalvariable.Add("Module@ModuleManageService", &ModuleManageService{})
	//moduleManageServiceName = configutil.ReadConfigKey("", "CloudServer", "BaseServerKey", "").(string)
}

/**
 * 读取树形结构数据
 * ctx Http请求对象
 */
func (service ModuleManageService) FindByTree(ctx *gin.Context) (bool, string, interface{}) {
	groupColumn := urlutil.GetParam(ctx.Request, "groupColumn", "").(string)
	groupName := urlutil.GetParam(ctx.Request, "groupName", "").(string)
	m := map[string]interface{}{
		"groupColumn": groupColumn,
		"groupName":   groupName,
	}

	bl, msg, data := BridgeDao{}.Post(ctx, moduleManageServiceName, "/module/manage/find/tree", m, &msgentity.MsgEntity{})
	if !bl {
		return bl, msg, data
	}

	me := data.(*msgentity.MsgEntity)

	return me.Success, me.Msg, me.Data
}
